/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.documentar.controller;

import br.com.documentar.interfacee.InterfaceController;
import br.com.documentar.model.RevendaModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Santos
 */
public class RevendaController implements InterfaceController<RevendaModel> {

    private final br.com.documentar.DAO.RevendaDAO dao = new br.com.documentar.DAO.RevendaDAO();

    @Override
    public RevendaModel getModel() {
        return new RevendaModel();
    }

    @Override
    public DefaultTableModel insertTableModel(RevendaModel model) {
        model.getModelTable().setNumRows(0);
        for (br.com.documentar.model.RevendaModel p : dao.getDados(model)) {
            model.getModelTable().addRow(new Object[]{p.getCodigo(), p.getNome(), p.getContato(), p.getAtivo()});
        }
        return model.getModelTable();
    }

    @Override
    public DefaultTableModel getDadosTableModel(RevendaModel model) {
        return insertTableModel(model);
    }

    @Override
    public boolean setDados(RevendaModel model) {
        return dao.setDados(model);
    }

    @Override
    public DefaultComboBoxModel getDadosComboBoxModel(RevendaModel model) {
        return insertComboBoxModel(model);
    }

    @Override
    public DefaultComboBoxModel insertComboBoxModel(RevendaModel model) {
        for (br.com.documentar.model.RevendaModel p : dao.getDados(model)) {
            model.getModelComboBox().addElement(p.getCodigo() + " - " + p.getNome());
        }
        return model.getModelComboBox();
    }
}
